const app = require('../app')
const {
  NAME_OR_PASSWORD_IS_REQUIRED,
  NAME_IS_ALREADY_EXISTS,
  NAME_IS_NOT_EXISTS,
  PASSWORD_IS_ERROR,
  UNAUTHORIZATION,
  OPERATION_IS_PERMISSION
} = require('../config/error')

app.on('error', (error, ctx) => {
  let code = 0
  let message = ''
  switch (error) {
    case NAME_OR_PASSWORD_IS_REQUIRED:
      code = -1001
      message = '用户名或者密码不能为空'
      break
    case NAME_IS_ALREADY_EXISTS:
      code = -1002
      message = '用户名已经被占用,不能使用'
      break
      case NAME_IS_NOT_EXISTS:
      code = -1003
      message = '该用户不存在，请检查用户名'
      break
      case PASSWORD_IS_ERROR:
        code = -1004
        message = '输入的密码错误，请重新输入密码'
        break
         case UNAUTHORIZATION:
        code = -1005
        message = 'token过期或者无效的token~'
        break
        case OPERATION_IS_PERMISSION:
          code = -1006
          message = '你没有操作权限'
          break

  }
  ctx.body = { code, message }
})
